package com.pinyoumei.app.activity.wallet;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.pinyoumei.app.R;
import com.pinyoumei.app.utils.Utils;

public class WalletCouponDialog1 extends Dialog {

    private Context context;
    private int layoutResID;//布局文件id
    private int[] listenedItems;//存放控件id的数组

    private String amount = Utils.red_package_amount+"";
    private String strTxt = "已为您自动领取¥"+amount+"红包，下单既可享受优惠";

    public WalletCouponDialog1(Context context, int layoutResID, int[] listenedItems){
        super(context, R.style.dialogStyle2);//这个决定dialog的样式
        this.context = context;
        this.layoutResID = layoutResID;
        this.listenedItems = listenedItems;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        Window window = getWindow();//获取一个窗口
        window.setGravity(Gravity.CENTER);//设置窗口的位置
//        window.setWindowAnimations(R.style.center_scale_animation);//设置窗口进入时的动画特效
        WindowManager.LayoutParams layoutParams = window.getAttributes();//获取窗口的属性赋值给layoutParams
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(layoutParams);//设置窗口的属性
        setCanceledOnTouchOutside(true);
        setContentView(R.layout.wallet_coupon_dialog_view);
        TextView wcdvTxt = findViewById(R.id.wcdv_txt);
        wcdvTxt.setText(strTxt);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                dismiss();
//                Intent intent = new Intent(context,WalletRechargeActivity.class);
//                context.startActivity(intent);
            }
        },2000);
    }

    @Override
    public void show(){
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        layoutParams.alpha=0.8f;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
    }

}
